$("#update-submission-close").click(function () {
    clearInfo();
    $('#noCard').modal('hide')
});
function clearInfo() {
    $("#update-submission-id").val("");
    $("#update-submission-paymentChannels").val("");
    $("#update-submission-complaintChannels").val("");
    $("#update-submission-complaintLine").val("");
    $("#update-submission-acceptanceTime").val("");
    $("#update-submission-processingResults").val("");
    $("#update-submission-complaintType").val("");
    $("#update-submission-dutyDetermine").val("");
    $("#update-submission-contactInformation").val("");
    $("#update-submission-registrar").val("");
    $("#update-submission-handler").val("");
    $("#update-submission-busCompany").val("");
    $("#update_submission_contentsComplaints").val("");
    $("#update_submission_processingTime").val("");
    $("#update_submission_processing").val("");
    $("#update-submission-remakes").val("");
}
function load_data(x){
    update_submission_paymentChannels();
    update_submission_complaintChannels();
    update_submission_complaintType();
    update_submission_dutyDetermine();
    update_submission_processing()
    if(x === null || x === ''){
        $MB.n_danger("系统异常，请重新操作");
        $('#update-submission').modal('hide')
    }
    var obj = new Object();
    obj.id = x;
    $.post(ctx+"handle/getByHandleId",obj,function(r){
        if (r.code !== 0) {
            $MB.n_danger(r.msg);
            $('#update-submission').modal('hide')
            return;
        }
        $("#update_submission_id").val(r.data.id);
        $("#update_submission_paymentChannels option:selected").text(r.data.paymentChannels);
        //$("#update_submission_complaintChannels option:selected").text(r.data.complaintChannels);
        $("#update_submission_complaintType option:selected").text(r.data.complaintType);
        //$("#update_submission_dutyDetermine option:selected").text(r.data.dutyDetermine);
        $("#update_submission_processing option:selected").text(r.data.processing);
        $("#update_submission_complaintLine").val(r.data.complaintLine);
        $("#update_submission_acceptanceTime").val(r.data.acceptanceTime);
        $("#update_submission_processingResults").val(r.data.processingResults);
        //$("#update_submission_contactInformation").val(r.data.contactInformation);
        $("#update_submission_registrar").val(r.data.registrar);
        $("#update_submission_handler").val(r.data.handler);
        //$("#update_submission_busCompany").val(r.data.busCompany);
        $("#update_submission_contentsComplaints").val(r.data.contentsComplaints);
        $("#update_submission_remakes").val(r.data.remakes);
        $("#update_submission_processingTime").val(r.data.processingTime);
    });
}

$(function () {

    $("#update-submission-save").click(function () {
        var id = $('#update_submission_id').val();
        var paymentChannels =$('#update_submission_paymentChannels option:selected').text();
        //var complaintChannels =$('#update_submission_complaintChannels option:selected').text();
        var processing =$('#update_submission_processing option:selected').text();


        var complaintLine = $("#update_submission_complaintLine").val();
        if(processing==="已处理"){
            if(complaintLine === null || complaintLine ===""){
                $MB.n_danger("请输入投诉路线！");
                $('#noCard').modal('hide')
                return;
            }
        }

        var contentsComplaints = $("#update_submission_contentsComplaints").val();
        if(processing==="已处理"){
            if(contentsComplaints === null || contentsComplaints ===""){
                $MB.n_danger("请输入投诉内容！");
                $('#noCard').modal('hide')
                return;
            }
        }

/*        var contactInformation = $("#update_submission_contactInformation").val();
        if(processing==="已处理"){
            if(contactInformation === null || contactInformation ===""){
                $MB.n_danger("请输入联系方式！");
                $('#noCard').modal('hide')
                return;
            }
        }*/

        var acceptanceTime = $("#update_submission_acceptanceTime").val();
        var processingResults = $("#update_submission_processingResults").val();
        if(processing==="已处理"){
            if(processingResults === null || processingResults ===""){
                $MB.n_danger("请输入处理结果！");
                $('#noCard').modal('hide')
                return;
            }
        }

        var registrar = $("#update_submission_registrar").val();
        if(processing==="已处理"){
            if(registrar === null || registrar ===""){
                $MB.n_danger("请输入登记人！");
                $('#noCard').modal('hide')
                return;
            }
        }

        var handler = $("#update_submission_handler").val();
        if(processing==="已处理"){
            if(handler === null || handler ===""){
                $MB.n_danger("请输入处理人！");
                $('#noCard').modal('hide')
                return;
            }
        }

/*        var busCompany = $("#update_submission_busCompany").val();
        if(processing==="已处理"){
            if(busCompany === null || busCompany ===""){
                $MB.n_danger("请输入公交公司！");
                $('#noCard').modal('hide')
                return;
            }
        }*/

        var complaintType =$('#update_submission_complaintType option:selected').text();


        var remakes = $("#update_submission_remakes").val();

        var processingTime = $("#update_submission_processingTime").val();

/*        if(processing==="已处理"){
            if(processingTime === null || processingTime ===""){
                $MB.n_danger("请输入处理时间！");
                $('#noCard').modal('hide')
                return;
            }
        }*/

/*        var dutyDetermine =$('#update_submission_dutyDetermine option:selected').text();
        if(processing==="已处理"){
            if(dutyDetermine === null || dutyDetermine ===""){
                $MB.n_danger("请输入责任判定！");
                $('#noCard').modal('hide')
                return;
            }

        }*/

        if(processing==="待处理" || processing ==="未处理"){
            if(processingTime !== ""){
                $MB.n_danger("投诉信息"+processing+"，请不要输入处理时间！");
                $('#noCard').modal('hide')
                return;
            }
        }

        var par = new Object()
        par.id = id;
        par.paymentChannels = paymentChannels;
        //par.complaintChannels = complaintChannels;
        par.complaintLine = complaintLine;
        par.acceptanceTime = acceptanceTime;
        par.processingResults = processingResults;
        par.complaintType = complaintType;
        //par.dutyDetermine = dutyDetermine;
        par.remakes = remakes;
        //par.contactInformation = contactInformation;
        par.registrar = registrar;
        par.handler = handler;
        //par.busCompany = busCompany;
        par.contentsComplaints = contentsComplaints;
        par.processing = processing;
        /*par.processingTime = processingTime;*/

        $.post(ctx+"handle/updateHandle",par,function (r) {
            if (r.code !== 0) {
                $MB.n_danger(r.msg);
                $('#noCard').modal('hide')
                return;
            }else{
                $MB.n_success("投诉信息已修改！");
                // print(r);
                $('#noCard').modal('hide')
                console.log(r)
                return;
            }
        });
    });

});


$("#noCard .btn-close").click(function () {
    closeModal();
});
function closeModal() {
    $MB.closeAndRestModal("noCard");
    clearInfo();
}

//初始化修改页面下拉选，加载受理支付渠道下拉选
function update_submission_paymentChannels() {
    $("#update_submission_paymentChannels").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"submission/pullDown?submissionKey=paymentChannels",

            success:function(result){
                $("#update_submission_paymentChannels").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_submission_paymentChannels").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

//初始化修改页面下拉选，加载投诉渠道下拉选
function update_submission_complaintChannels() {
    $("#update_submission_complaintChannels").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"submission/pullDown?submissionKey=complaintChannels",

            success:function(result){
                $("#update_submission_complaintChannels").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_submission_complaintChannels").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}


//初始化修改页面下拉选，加载投诉类别下拉选
function update_submission_complaintType() {
    $("#update_submission_complaintType").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"submission/pullDown?submissionKey=complaintType",

            success:function(result){
                $("#update_submission_complaintType").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_submission_complaintType").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

//初始化修改页面下拉选，加载责任判定下拉选
function update_submission_dutyDetermine() {
    $("#update_submission_dutyDetermine").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"submission/pullDown?submissionKey=dutyDetermine",

            success:function(result){
                $("#update_submission_dutyDetermine").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_submission_dutyDetermine").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

//初始化修改页面下拉选，加载处理状态下拉选
function update_submission_processing() {
    $("#update_submission_processing").empty();
    $.ajax({
            type:"get",
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            url:ctx+"submission/pullDown?submissionKey=processing",

            success:function(result){
                $("#update_submission_processing").append("<option value=\"\" selected=\"selected\" disabled=\"disabled\"  style='display: none'></option>");
                $.each(result,function(index,value){

                    $("#update_submission_processing").append("<option value='"+value.id+"'>"+value.submissionValue+"</option>");

                })
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            },
            async:false             //false表示同步
        }

    );
}

/**
 * 每日报文
 */
$(function () {
    $("#message").click(function () {
        $.post(ctx+"submission/message",function (r) {
            if (r.code !== 0) {
                $MB.n_danger(r.msg);
                $('#noCard').modal('hide')
                return;
            }else{
                $MB.n_success("每日报文已发送！");
                // print(r);
                $('#noCard').modal('hide')
                console.log(r)
                return;
            }
        });
    });

});